package ca.inrs.ete.app.shopx;

import ca.inrs.ete.app.shopx.util.Constants;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.os.Bundle;



public class MainMenu {

	public static void onMenuSettings (Activity activity) {
		Intent intent = new Intent(activity, SHOPSettings.class);
		activity.startActivity(intent);
	}

	public static void onMenuSync (Activity activity) {
		AccountManager am = AccountManager.get(activity);
		Account[] accounts = am.getAccounts();

		// TODO: create account if empty
		for (Account account : accounts) {
			int isSyncable = ContentResolver.getIsSyncable(account, Constants.CONTENT_AUTHORITY);
			if (isSyncable > 0) {
				activity.setProgressBarVisibility(true);
				Bundle extras = new Bundle();
				extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
				ContentResolver.requestSync(accounts[0], Constants.CONTENT_AUTHORITY, extras);
			}
		}
	}

	public static void onMenuHelp(Activity activity) {
		/*    	
    	Intent intent = new Intent(this, SettingsActivity.class);
    	EditText editText = (EditText) findViewById(R.id.prm_url_url);
    	String message = editText.getText().toString();
    	intent.putExtra(EXTRA_MESSAGE, message);
    	startActivity(intent);
		 */    	
	}

	public static void onMenuAbout(Activity activity) {
		SHOPHelpAbout about = new SHOPHelpAbout(activity);
		about.setTitle(activity.getString(R.string.about_title));
		about.show();
	}

}
